using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace Bll
{
	class CQuestionManage
	{
		public static CQuestion CreateQuestion()
       {      
           return   new CQuestion();
       }
	   
	   public static CQuestion Save(CQuestion question)
	   {
			try
           {
               int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_AddQuestion", question.ID, question.email, question.userID, question.name, question.type, question.questionContent, question.questionTime, question.questionType, question.questionTitle);
             
				if(0 == num)
                   return null;
                return question;
           }
           catch (Exception e)
           {
               return null;
           }
	   }
	   
	   public static bool Update(CQuestion question)
	   {
			try
			{
                int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_SaveQuestion", question.ID, question.email, question.userID, question.name, question.type, question.questionContent, question.questionTime, question.questionType, question.questionTitle);
				if (0 == num)
                   return false;
				return true;
			}
			catch (Exception e)
			{
               return false;
			}
	   }
	   
	   public static bool Delete(CQuestion question)
	   {
			try
			{
				int num = BLL.SqlHelper.ExecuteNonQuery(CConnection.getConnString(), "sp_RemoveQuestion", question.ID);
				if (0 == num)
                   return false;
				return true;
			}
			catch (Exception e)
			{
               return false;
			}
	   }
	   
	   static CQuestion GetQuestion(String ID)
	   {
           SqlDataReader reader = BLL.SqlHelper.ExecuteReader(CConnection.getConnString(), "sp_GetQuestion", ID);
			try
           {             
               if (reader.Read())
               { 
					CQuestion question = new CQuestion();
					question.email = reader["email"].ToString();
					question.userID = reader["userID"].ToString();
					question.name = reader["name"].ToString();
					//question.type = reader["type"].ToString();
					question.questionContent = reader["questionContent"].ToString();
					//question.questionTime = reader["questionTime"].ToString();
                   question.questionType = reader["questionType"].ToString();
                   question.questionTitle = reader["questionTitle"].ToString();
					
					reader.Close();
					return question;
               }
			   reader.Close();
               return null;
           }
           catch (Exception e)
           {

               //reader.Close();
               return null;
           }
            finally
            {
                reader.Close();
            }
	   }
	}
}